﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/MasterPage.master" AutoEventWireup="true"
    CodeFile="RolesList.aspx.cs" Inherits="admin_system_RolesList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head_Title" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Head" runat="Server">
    <script src="/Plugin/jqueryEasyui/jquery.easyui.min.js" type="text/javascript"></script>
    <link href="/Plugin/jqueryEasyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="/Plugin/jqueryEasyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/sjn.1.js" type="text/javascript"></script>
    <style type="text/css">
        .tree-node {
            height: 25px;
            line-height: 25px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Title" runat="Server">
    系统管理 - 角色管理
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Control" runat="Server">
    <div style="height: 30px;">
        <a href="#" class="easyui-linkbutton" style="float: right; margin-top: 2px; margin-right: 20px;"
            data-options="plain:true,iconCls:'icon-save'" onclick="updateMenu()">保存权限配置</a>
        <a href="#" class="easyui-linkbutton" style="float: right; margin-top: 2px;" data-options="plain:true,iconCls:'icon-add'"
            onclick="AddAlter()">添加角色</a>
    </div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Content" runat="Server">
    <script language="javascript" type="text/javascript">

        $(function () {

            //初始化角色列表
            $("#RolesList").datagrid({
                url: "RolesList.aspx?fun=getRoleList",
                title: "角色列表",
                singleSelect: true,
                height: $("#divBody").height(),
                columns: [[
                    { title: "角色名称", field: "RoleName", width: 150, halign: "center" },
                    {
                        title: "状态", field: "IsDisabled", width: 70, align: "center",
                        formatter: function (value, row, index) {
                            if (value) {
                                return "开启";
                            } else {
                                return "禁用";
                            }
                        }
                    },
                    {
                        title: "创建时间", field: "CreateTime", width: 130, align: "center",
                        formatter: function (value, row, index) {
                            return sjn.toDate(value).format();
                        }
                    },
                    {
                        title: "操作", field: "tool", width: 90, align: "center",
                        formatter: function (value, row, index) {
                            var htm = '<a href="#" class="easyui-linkbutton" onclick="EditAlter(\'' + row.RoleID + '\')" data-options="plain:true">编辑</a>';
                            return htm;
                        }
                    }
                ]],
                onClickRow: function (rowIndex, rowData) {
                    var checkeds = $("#menuTree").tree("getChecked");
                    $(checkeds).each(function (i, item) {
                        $("#menuTree").tree("uncheck", item.target);
                    });
                    $(rowData.T_MenuInRoles).each(function (i, item) {
                        var node = $('#menuTree').tree('find', item.MenuID);
                        if (node.children.length == 0) {
                            $("#menuTree").tree("check", node.target);
                        }

                    });

                }
            });

            //初始化菜单树
            $("#menuTree").tree({
                title: "sdfsdf",
                url: "RolesList.aspx?fun=getMenuTrr",
                checkbox: true,
                cascadeCheck: true
            });

        });

        //“添加” 按钮事件
        var AddAlter = function () {
            art.dialog.open('<%=MyUrl.ToAb("~/Admin/system/") %>RolesDetail.aspx?act=add',
                            {
                                title: "添加角色",
                                id: 'AddAlter',
                                lock: true,
                                width: 550,
                                height: 250,
                                close: function () {
                                    var refresh = art.dialog.data("Refresh");
                                    if (refresh == "true") {
                                        location.href = location.href;
                                    }
                                }
                            });
        };

        //“编辑” 按钮事件
        var EditAlter = function (id) {
            art.dialog.open('<%=MyUrl.ToAb("~/Admin/system/") %>RolesDetail.aspx?act=edit&id=' + id,
                            {
                                title: "编辑角色",
                                id: 'EditAlter',
                                lock: true,
                                width: 550,
                                height: 260,
                                close: function () {
                                    var refresh = art.dialog.data("Refresh");
                                    if (refresh == "true") {
                                        location.href = location.href;
                                    }
                                }
                            });
        };

        //“保存权限配置” 按钮事件
        var updateMenu = function () {
            var loading = art.dialog.loadingTip("数据加载中。。。");
            var checks = $("#menuTree").tree("getChecked", ['checked', 'indeterminate']);
            var selRole = $("#RolesList").datagrid("getSelected");
            var idsStr = "", roleId = "";

            //判断是否选择角色
            if (selRole == null) {
                art.dialog.alert('请选择要配置菜单权限的角色！');
                loading.close();
                return;
            }
            roleId = selRole.RoleID;

            $(checks).each(function (i, item) {
                idsStr += item.id + ",";
            });
            $.post("rolesList.aspx?fun=updateMenu",
                    {
                        roleId: roleId,
                        menuIds: idsStr
                    },
                    function (ms) {
                        $("#RolesList").datagrid("reload");
                        artDialog.alert(ms.info);
                        loading.close();
                    }, "json")

        };

        //全选
        var allCheck = function () {
            var unchecked = $("#menuTree").tree("getChecked", "unchecked");
            $(unchecked).each(function (i, item) {
                if (item.children.length == 0) {
                    $("#menuTree").tree("check", item.target);
                }
            })
        }

        var allUncheck = function () {
            var checked = $("#menuTree").tree("getChecked", ['checked', 'indeterminate']);
            $(checked).each(function (i, item) {
                if (item.children.length == 0) {
                    $("#menuTree").tree("uncheck", item.target);
                }
            })
        }

    </script>
    <div id="divBody" style="min-width: 930px; max-width: 100%; height: 100%">
        <table style="width: 100%">
            <tr>
                <td style="width: 450px; height: 100%; vertical-align: top;">
                    <table id="RolesList">
                    </table>
                </td>
                <td  style=" vertical-align:top;">
                    <div style="min-width: 400px; max-width: 100%;" class="panel-header">
                        <div class="panel-title">
                            系统菜单树
                        </div>
                    </div>
                    <div class="datagrid-toolbar" style="height: 28px;">
                        <a href="#" class="easyui-linkbutton" style="margin-top: 2px; float: left;" onclick="allCheck()" data-options="plain:true,iconCls:'icon-add'">全选</a> <a href="#" class="easyui-linkbutton" style="margin-top: 2px; float: left;"
                            data-options="plain:true,iconCls:'icon-add'" onclick="allUncheck()">全不选</a> <a href="#" class="easyui-linkbutton"
                                style="margin-top: 2px; float: left;" data-options="plain:true,iconCls:'icon-add'" onclick='$("#menuTree").tree("expandAll");'>全部展开</a> <a href="#" class="easyui-linkbutton" style="margin-top: 2px; float: left;"
                                    data-options="plain:true,iconCls:'icon-add'" onclick='$("#menuTree").tree("collapseAll");'>全部合闭</a>
                    </div>
                    <ul id="menuTree">
                    </ul>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Foot" runat="Server">
    <div id="div_page" runat="server">
    </div>
</asp:Content>
